/*     */ package com.wgcloud.controller;
/*     */ import cn.hutool.core.collection.CollectionUtil;
/*     */ import cn.hutool.core.comparator.PropertyComparator;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.wgcloud.config.CommonConfig;
/*     */ import com.wgcloud.dto.ChartReportInfo;
/*     */ import com.wgcloud.entity.AppInfo;
/*     */ import com.wgcloud.entity.HeathMonitor;
/*     */ import com.wgcloud.entity.PortInfo;
/*     */ import com.wgcloud.entity.SystemInfo;
/*     */ import com.wgcloud.service.AppInfoService;
/*     */ import com.wgcloud.service.HeathMonitorService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.PortInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import com.wgcloud.service.TaskUtilService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.FormatUtil;
/*     */ import com.wgcloud.util.ThreadPoolUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collections;
/*     */ import java.util.Comparator;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/report"})
/*     */ public class ReportCotroller {
/*     */   private void testThread() {
/*  43 */     Runnable runnable = () -> logger.info("ReportCotroller----------testThread");
/*     */ 
/*     */     
/*  46 */     ThreadPoolUtil.executor.execute(runnable);
/*     */   }
/*     */ 
/*     */   
/*  50 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.ReportCotroller.class);
/*     */   
/*     */   @Autowired
/*     */   TaskUtilService taskUtilService;
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */   
/*     */   @Resource
/*     */   private HeathMonitorService heathMonitorService;
/*     */   
/*     */   @Resource
/*     */   private AppInfoService appInfoService;
/*     */   
/*     */   @Resource
/*     */   private PortInfoService portInfoService;
/*     */   
/*     */   @Autowired
/*     */   CommonConfig commonConfig;
/*     */ 
/*     */   
/*     */   @RequestMapping({"index"})
/*     */   public String index(Model model, HttpServletRequest request) {
/*  76 */     Map<String, Object> params = new HashMap<>();
/*  77 */     String days = request.getParameter("days");
/*  78 */     if (StringUtils.isEmpty(days)) {
/*  79 */       days = "1";
/*     */     }
/*     */ 
/*     */     
/*  83 */     if (!StaticKeys.LICENSE_STATE.equals("1")) {
/*  84 */       int dayInt = Integer.valueOf(days).intValue();
/*  85 */       if (dayInt > 7) {
/*  86 */         days = "7";
/*  87 */         model.addAttribute("msg", "个人版只能查看最近7天图表，请点击页面底部网站，联系我们升级到专业版");
/*     */       } 
/*     */     } 
/*     */ 
/*     */     
/*  92 */     model.addAttribute("days", days);
/*     */     
/*     */     try {
/*  95 */       setMainBarChart(model, days);
/*     */       
/*  97 */       setPieChart(model, days);
/*     */       
/*  99 */       setTop10BarChart(model, days);
/*     */       
/* 101 */       setTop10HeathChart(model, days);
/*     */       
/* 103 */       setTop10AppChart(model, days);
/*     */       
/* 105 */       setTop10PortChart(model, days);
/*     */     }
/* 107 */     catch (Exception e) {
/* 108 */       logger.error("统计分析报表告警次数错误", e);
/*     */     } 
/* 110 */     return "report/index";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setMainBarChart(Model model, String days) throws Exception {
/* 120 */     Map<String, Object> params = new HashMap<>();
/* 121 */     List<ChartReportInfo> chartInfoList = new ArrayList<>();
/* 122 */     params.put("hostname", "告警");
/*     */     try {
/* 124 */       List<String> dateList = getDateList(Integer.valueOf(days).intValue());
/* 125 */       for (String dateStr : dateList) {
/* 126 */         if ("1".equals(days)) {
/* 127 */           for (int i = 0; i < 24; i++) {
/* 128 */             String startHour = "" + i;
/* 129 */             if (i < 10) {
/* 130 */               startHour = "0" + i;
/*     */             }
/* 132 */             params.put("startTime", dateStr + " " + startHour + ":00:00");
/* 133 */             params.put("endTime", dateStr + " " + startHour + ":59:59");
/* 134 */             int j = this.logInfoService.countByParams(params);
/* 135 */             ChartReportInfo chartReportInfo = new ChartReportInfo();
/* 136 */             chartReportInfo.setName(startHour + "时");
/* 137 */             chartReportInfo.setVote(Integer.valueOf(j));
/* 138 */             chartInfoList.add(chartReportInfo);
/*     */           }  continue;
/*     */         } 
/* 141 */         params.put("startTime", dateStr + " 00:00:00");
/* 142 */         params.put("endTime", dateStr + " 23:59:59");
/* 143 */         int size = this.logInfoService.countByParams(params);
/* 144 */         ChartReportInfo chartInfo = new ChartReportInfo();
/* 145 */         if (dateStr.length() > 5) {
/* 146 */           chartInfo.setName(dateStr.substring(5));
/*     */         }
/* 148 */         chartInfo.setVote(Integer.valueOf(size));
/* 149 */         chartInfoList.add(chartInfo);
/*     */       } 
/*     */       
/* 152 */       model.addAttribute("mainBarChart", JSONUtil.parseArray(chartInfoList));
/* 153 */     } catch (Exception e) {
/* 154 */       logger.error("统计分析顶部柱状图告警次数错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setPieChart(Model model, String days) {
/* 165 */     Map<String, Object> params = new HashMap<>();
/* 166 */     List<ChartReportInfo> chartInfoList = new ArrayList<>();
/* 167 */     params.put("hostname", "告警");
/*     */     try {
/* 169 */       List<String> dateList = getDateList(Integer.valueOf(days).intValue());
/* 170 */       if (!CollectionUtil.isEmpty(dateList)) {
/* 171 */         String startDay = dateList.get(0);
/* 172 */         String endDay = dateList.get(dateList.size() - 1);
/* 173 */         params.put("startTime", startDay + " 00:00:00");
/* 174 */         params.put("endTime", endDay + " 23:59:59");
/*     */         
/* 176 */         int size = this.logInfoService.countByParams(params);
/* 177 */         if (size == 0) {
/*     */           return;
/*     */         }
/*     */         
/* 181 */         params.put("hostname", "进程下线告警");
/* 182 */         int appSize = this.logInfoService.countByParams(params);
/* 183 */         double a = appSize / size;
/* 184 */         ChartReportInfo c1 = new ChartReportInfo();
/* 185 */         c1.setName("进程下线告警次数");
/* 186 */         c1.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 187 */         chartInfoList.add(c1);
/*     */         
/* 189 */         params.put("hostname", "端口telnet不通告警");
/* 190 */         int portSize = this.logInfoService.countByParams(params);
/* 191 */         a = portSize / size;
/* 192 */         ChartReportInfo c2 = new ChartReportInfo();
/* 193 */         c2.setName("端口下线告警次数");
/* 194 */         c2.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 195 */         chartInfoList.add(c2);
/*     */         
/* 197 */         params.put("hostname", "日志监控告警");
/* 198 */         int fileWarnSize = this.logInfoService.countByParams(params);
/* 199 */         a = fileWarnSize / size;
/* 200 */         ChartReportInfo c3 = new ChartReportInfo();
/* 201 */         c3.setName("日志监控告警次数");
/* 202 */         c3.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 203 */         chartInfoList.add(c3);
/*     */         
/* 205 */         params.put("hostname", "docker下线告警");
/* 206 */         int dockerSize = this.logInfoService.countByParams(params);
/* 207 */         a = dockerSize / size;
/* 208 */         ChartReportInfo c4 = new ChartReportInfo();
/* 209 */         c4.setName("docker下线告警次数");
/* 210 */         c4.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 211 */         chartInfoList.add(c4);
/*     */         
/* 213 */         params.put("hostname", "数通设备PING超时告警");
/* 214 */         int dceSize = this.logInfoService.countByParams(params);
/* 215 */         a = dceSize / size;
/* 216 */         ChartReportInfo c5 = new ChartReportInfo();
/* 217 */         c5.setName("数通设备告警次数");
/* 218 */         c5.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 219 */         chartInfoList.add(c5);
/*     */         
/* 221 */         params.put("hostname", "数据源连接失败告警");
/* 222 */         int dbSize = this.logInfoService.countByParams(params);
/* 223 */         a = dbSize / size;
/* 224 */         ChartReportInfo c6 = new ChartReportInfo();
/* 225 */         c6.setName("数据源告警次数");
/* 226 */         c6.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 227 */         chartInfoList.add(c6);
/*     */         
/* 229 */         params.put("hostname", "服务接口检测告警");
/* 230 */         int heathSize = this.logInfoService.countByParams(params);
/* 231 */         a = heathSize / size;
/* 232 */         ChartReportInfo c7 = new ChartReportInfo();
/* 233 */         c7.setName("服务接口告警次数");
/* 234 */         c7.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 235 */         chartInfoList.add(c7);
/*     */         
/* 237 */         a = (size - appSize - portSize - fileWarnSize - dockerSize - dceSize - dbSize - heathSize) / size;
/* 238 */         ChartReportInfo c8 = new ChartReportInfo();
/* 239 */         c8.setName("主机及其资源告警次数");
/* 240 */         c8.setValue(Double.valueOf(FormatUtil.formatDouble(Double.valueOf(a), 2)));
/* 241 */         chartInfoList.add(c8);
/*     */       } 
/* 243 */       model.addAttribute("pieChart", JSONUtil.parseArray(chartInfoList));
/* 244 */     } catch (Exception e) {
/* 245 */       logger.error("统计分析饼图告警次数错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setTop10BarChart(Model model, String days) throws Exception {
/* 256 */     Map<String, Object> params = new HashMap<>();
/* 257 */     List<ChartReportInfo> chartInfoList = new ArrayList<>();
/*     */     try {
/* 259 */       List<String> dateList = getDateList(Integer.valueOf(days).intValue());
/* 260 */       String startDay = dateList.get(0);
/* 261 */       String endDay = dateList.get(dateList.size() - 1);
/* 262 */       params.put("startTime", startDay + " 00:00:00");
/* 263 */       params.put("endTime", endDay + " 23:59:59");
/* 264 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(params);
/* 265 */       for (SystemInfo systemInfo : systemInfoList) {
/* 266 */         params.put("hostname", systemInfo.getHostname());
/* 267 */         int size = this.logInfoService.countByParams(params);
/* 268 */         ChartReportInfo chartInfo = new ChartReportInfo();
/* 269 */         chartInfo.setName(systemInfo.getHostname());
/* 270 */         chartInfo.setVote(Integer.valueOf(size));
/* 271 */         chartInfoList.add(chartInfo);
/*     */       } 
/* 273 */       Collections.sort(chartInfoList, (Comparator<? super ChartReportInfo>)new PropertyComparator("vote"));
/*     */ 
/*     */       
/* 276 */       List<ChartReportInfo> chartInfoListTmp2 = new ArrayList<>();
/* 277 */       if (chartInfoList.size() > 10) {
/* 278 */         chartInfoListTmp2 = chartInfoList.subList(0, 10);
/*     */       } else {
/* 280 */         chartInfoListTmp2 = chartInfoList;
/*     */       } 
/* 282 */       model.addAttribute("top10LowBarChart", JSONUtil.parseArray(chartInfoListTmp2));
/*     */ 
/*     */ 
/*     */       
/* 286 */       CollectionUtil.reverse(chartInfoList);
/* 287 */       List<ChartReportInfo> chartInfoListTmp = new ArrayList<>();
/* 288 */       if (chartInfoList.size() > 10) {
/* 289 */         chartInfoListTmp = chartInfoList.subList(0, 10);
/*     */       } else {
/* 291 */         chartInfoListTmp = chartInfoList;
/*     */       } 
/* 293 */       model.addAttribute("top10BarChart", JSONUtil.parseArray(chartInfoListTmp));
/*     */     }
/* 295 */     catch (Exception e) {
/* 296 */       logger.error("统计分析主机及资源告警次数TOP10错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setTop10HeathChart(Model model, String days) throws Exception {
/* 307 */     Map<String, Object> params = new HashMap<>();
/* 308 */     List<ChartReportInfo> chartInfoList = new ArrayList<>();
/*     */     try {
/* 310 */       List<HeathMonitor> heathMonitorList = this.heathMonitorService.selectAllByParams(params);
/* 311 */       List<String> dateList = getDateList(Integer.valueOf(days).intValue());
/* 312 */       String startDay = dateList.get(0);
/* 313 */       String endDay = dateList.get(dateList.size() - 1);
/* 314 */       params.put("startTime", startDay + " 00:00:00");
/* 315 */       params.put("endTime", endDay + " 23:59:59");
/* 316 */       for (HeathMonitor heathMonitor : heathMonitorList) {
/* 317 */         params.put("hostname", heathMonitor.getAppName());
/* 318 */         int size = this.logInfoService.countByParams(params);
/* 319 */         ChartReportInfo chartInfo = new ChartReportInfo();
/* 320 */         chartInfo.setName(heathMonitor.getAppName());
/* 321 */         chartInfo.setVote(Integer.valueOf(size));
/* 322 */         chartInfoList.add(chartInfo);
/*     */       } 
/* 324 */       Collections.sort(chartInfoList, (Comparator<? super ChartReportInfo>)new PropertyComparator("vote"));
/*     */ 
/*     */       
/* 327 */       CollectionUtil.reverse(chartInfoList);
/* 328 */       List<ChartReportInfo> chartInfoListTmp = new ArrayList<>();
/* 329 */       if (chartInfoList.size() > 10) {
/* 330 */         chartInfoListTmp = chartInfoList.subList(0, 10);
/*     */       } else {
/* 332 */         chartInfoListTmp = chartInfoList;
/*     */       } 
/* 334 */       model.addAttribute("top10HeathChart", JSONUtil.parseArray(chartInfoListTmp));
/*     */     }
/* 336 */     catch (Exception e) {
/* 337 */       logger.error("统计分析服务接口告警次数图表错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setTop10AppChart(Model model, String days) throws Exception {
/* 348 */     Map<String, Object> params = new HashMap<>();
/* 349 */     List<ChartReportInfo> chartInfoList = new ArrayList<>();
/*     */     try {
/* 351 */       List<AppInfo> appInfoList = this.appInfoService.selectAllByParams(params);
/* 352 */       List<String> dateList = getDateList(Integer.valueOf(days).intValue());
/* 353 */       String startDay = dateList.get(0);
/* 354 */       String endDay = dateList.get(dateList.size() - 1);
/* 355 */       params.put("startTime", startDay + " 00:00:00");
/* 356 */       params.put("endTime", endDay + " 23:59:59");
/*     */       
/* 358 */       Set<String> set = new HashSet<>();
/* 359 */       for (AppInfo appInfo : appInfoList) {
/* 360 */         set.add(appInfo.getAppName());
/*     */       }
/*     */       
/* 363 */       for (String appName : set) {
/* 364 */         params.put("hostname", appName);
/* 365 */         int size = this.logInfoService.countByParams(params);
/* 366 */         ChartReportInfo chartInfo = new ChartReportInfo();
/* 367 */         chartInfo.setName(appName);
/* 368 */         chartInfo.setVote(Integer.valueOf(size));
/* 369 */         chartInfoList.add(chartInfo);
/*     */       } 
/* 371 */       Collections.sort(chartInfoList, (Comparator<? super ChartReportInfo>)new PropertyComparator("vote"));
/*     */ 
/*     */       
/* 374 */       CollectionUtil.reverse(chartInfoList);
/* 375 */       List<ChartReportInfo> chartInfoListTmp = new ArrayList<>();
/* 376 */       if (chartInfoList.size() > 10) {
/* 377 */         chartInfoListTmp = chartInfoList.subList(0, 10);
/*     */       } else {
/* 379 */         chartInfoListTmp = chartInfoList;
/*     */       } 
/* 381 */       model.addAttribute("top10AppInfoChart", JSONUtil.parseArray(chartInfoListTmp));
/*     */     }
/* 383 */     catch (Exception e) {
/* 384 */       logger.error("统计分析进程告警次数图表错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setTop10PortChart(Model model, String days) throws Exception {
/* 395 */     Map<String, Object> params = new HashMap<>();
/* 396 */     List<ChartReportInfo> chartInfoList = new ArrayList<>();
/*     */     try {
/* 398 */       List<PortInfo> portInfoList = this.portInfoService.selectAllByParams(params);
/* 399 */       List<String> dateList = getDateList(Integer.valueOf(days).intValue());
/* 400 */       String startDay = dateList.get(0);
/* 401 */       String endDay = dateList.get(dateList.size() - 1);
/* 402 */       params.put("startTime", startDay + " 00:00:00");
/* 403 */       params.put("endTime", endDay + " 23:59:59");
/*     */       
/* 405 */       Set<String> set = new HashSet<>();
/* 406 */       for (PortInfo portInfo : portInfoList) {
/* 407 */         set.add(portInfo.getPortName());
/*     */       }
/*     */       
/* 410 */       for (String portName : set) {
/* 411 */         params.put("hostname", portName);
/* 412 */         int size = this.logInfoService.countByParams(params);
/* 413 */         ChartReportInfo chartInfo = new ChartReportInfo();
/* 414 */         chartInfo.setName(portName);
/* 415 */         chartInfo.setVote(Integer.valueOf(size));
/* 416 */         chartInfoList.add(chartInfo);
/*     */       } 
/* 418 */       Collections.sort(chartInfoList, (Comparator<? super ChartReportInfo>)new PropertyComparator("vote"));
/*     */ 
/*     */       
/* 421 */       CollectionUtil.reverse(chartInfoList);
/* 422 */       List<ChartReportInfo> chartInfoListTmp = new ArrayList<>();
/* 423 */       if (chartInfoList.size() > 10) {
/* 424 */         chartInfoListTmp = chartInfoList.subList(0, 10);
/*     */       } else {
/* 426 */         chartInfoListTmp = chartInfoList;
/*     */       } 
/* 428 */       model.addAttribute("top10PortInfoChart", JSONUtil.parseArray(chartInfoListTmp));
/*     */     }
/* 430 */     catch (Exception e) {
/* 431 */       logger.error("统计分析端口告警次数图表错误", e);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public List<String> getDateList(int days) {
/* 442 */     List<String> dateList = new ArrayList<>();
/* 443 */     String nowTime = DateUtil.getCurrentDateTime();
/* 444 */     String sevenDayBefore = DateUtil.getDateBefore(nowTime, days);
/* 445 */     for (int i = 1; i < days + 1; i++) {
/* 446 */       sevenDayBefore = DateUtil.getDateBefore(nowTime, i);
/* 447 */       dateList.add(sevenDayBefore.substring(0, 10));
/*     */     } 
/* 449 */     CollectionUtil.reverse(dateList);
/* 450 */     return dateList;
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/ReportCotroller.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */